package com.fang.transfer.file.listener;

import com.fang.transfer.file.ThreadContext;
import com.fang.transfer.file.common.NettyHandle;
import com.fang.transfer.file.common.RequestListener;
import com.fang.transfer.file.common.code.ClientSendCode;
import com.fang.transfer.file.common.code.ServiceSendCode;
import com.fang.transfer.file.common.model.TransferFileRequest;
import com.fang.transfer.file.common.model.User;
import com.fang.transfer.file.service.FileSendRequestService;
import com.fang.transfer.file.service.UserService;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 检查文件下标完成进度
 */
@Service
public class CheckFileIndexListener extends RequestListener<TransferFileRequest> {



    @Autowired
    private FileSendRequestService fileSendRequestService;

    @Autowired
    private NettyHandle nettyHandle;

    @Override
    public void handle(TransferFileRequest param) {
        TransferFileRequest service = fileSendRequestService.getById(param.getId());
        User receiveUser = service.getReceiveUser();
        nettyHandle.send(receiveUser.getId(), ServiceSendCode.FILE_CHECK, service);
    }

    @Override
    public String getCode() {
        return ClientSendCode.SEND_FILE_FINISH_TO_RECEIVE;
    }
}
